package com.example.lxs_demo1.Common;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.lxs_demo1.R;


public class NormalTitleBar extends RelativeLayout {

    private ImageView ivLogo,ivRightSet;
    private TextView tvTitle;
    private RelativeLayout rl_navigation_bar;
    private Context context;

    public NormalTitleBar(Context context) {
        super(context, null);
        this.context = context;
    }

    public NormalTitleBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        View.inflate(context, R.layout.common_navigation_bar, this);
        ivLogo = (ImageView) findViewById(R.id.iv_logo);

        ivRightSet = (ImageView) findViewById(R.id.iv_right_set);
        rl_navigation_bar = (RelativeLayout) findViewById(R.id.rl_navigation_bar);
    }

    /**
     * 管理返回按钮
     */
    public void setBackVisibility(boolean visible) {
        if (visible) {
            ivLogo.setVisibility(View.VISIBLE);
        } else {
            ivLogo.setVisibility(View.GONE);
        }
    }

    /**
     * 右图标
     */
    public void setRightImagVisibility(boolean visible) {
        ivRightSet.setVisibility(visible ? View.VISIBLE : View.GONE);
    }

    public void setRightImagSrc(int id) {
        ivRightSet.setVisibility(View.VISIBLE);
        ivRightSet.setImageResource(id);
    }

    /**
     * 获取右按图标
     * @return
     */
    public View getRightImage() {
        return ivRightSet;
    }

    /**
     * 管理标题
     */
    public void setTitleVisibility(boolean visible) {
        if (visible) {
            tvTitle.setVisibility(View.VISIBLE);
        } else {
            tvTitle.setVisibility(View.GONE);
        }
    }

    /**
     * 设置标题
     * @param string
     */
    public void setTitleText(String string) {
        tvTitle.setVisibility(View.VISIBLE);
        tvTitle.setText(string);
    }

    public void setTitleColor(int color) {
        tvTitle.setTextColor(color);
    }

    public void setTitleSize(float size){
        tvTitle.setTextSize(size);
    }


    /*
     * 点击事件
     */
    public void setOnBackListener(OnClickListener listener) {

        ivLogo.setOnClickListener(listener);
    }

    public void setOnRightImagListener(OnClickListener listener) {
        ivRightSet.setOnClickListener(listener);

    }


    /**
     * 标题背景颜色
     *
     * @param color
     */
    public void setBackGroundColor(int color) {
        rl_navigation_bar.setBackgroundColor(color);
    }
    public Drawable getBackGroundDrawable() {
        return rl_navigation_bar.getBackground();
    }


}
